package Demo5;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Main23 {
   static int result =0;
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer>callable1=new Callable<>() {
            @Override
            public Integer call() throws Exception {
                for (int i = 0; i <100 ; i++) {
                  result++;
                }
return result;
            }
        };

        Runnable r=new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i <100 ; i++) {
                    result++;
                }
            }
        };

        FutureTask<Integer>futureTask=new FutureTask<>(callable1);
        FutureTask<Integer>futureTask1=new FutureTask<>(callable1);
      //  Thread t1=new Thread(r);
        //Thread t2=new Thread(r);

        Thread t1=new Thread(futureTask);
        Thread t2=new Thread(futureTask1);

        t1.start();
      t2.start();
        t1.join();
        t2.join();
        while(true){
            if(futureTask.isDone()&&futureTask1.isDone()){
                System.out.println(result);
                return;
            }

        }
    }
}
